import http from '../http/index.js'

export const notifications = (page) => {
	if(!page) page = 1
	return http.request({
		url : 'v5/notifications/threads',
		type : 'GET',
		data : {
			access_token : uni.getStorageSync('access_token'),
			page : page,
		}
	})
}

export const events = (page) => {
	if (!page ) page = 1
	return http.request({
		url : "v3/users/monkeyshuang/events",
		type : "GET",
		data : {access_token : uni.getStorageSync('access_token'),page : page}
	})
}

export const myinfo = () => {
	return http.request({
		url : "v5/user",
		type : "GET",
		data : {access_token : uni.getStorageSync('access_token')}		
	})
	// let user_id = uni.getStorageSync('user_id');
	// return http.request({
	// 	url : "v3/users/" + uni.getStorageSync('user_id'),
	// 	type : "GET",
	// 	data : {private_token : uni.getStorageSync('private_token')}
	// })
}

export const getOne = (username) => {
	return http.request({
		url : "v5/users/"+username,
		type : "GET",
		data : {access_token : uni.getStorageSync('access_token')}		
	})
}

export const changeName = (name) => {
	return http.request({
		url : "v5/user",
		method: "PATCH",
		data : {access_token : uni.getStorageSync('access_token') , name  : name} 
	})
}

export const changeWeibo = (weibo) => {
	return http.request({
		url : "v5/user",
		method: "PATCH",
		data : {access_token : uni.getStorageSync('access_token') , weibo : weibo}
	})
}

export const changeBio = (bio) => {
	return http.request({
		url : "v3/users/" + uni.getStorageSync('user_id'),
		method: "PUT",
		data : {private_token : uni.getStorageSync('private_token') , bio : bio},
	})
}

export const changeBlog = (blog) => {
	return http.request({
		url : "v5/user",
		method: "PATCH",
		data : {private_token : uni.getStorageSync('private_token') , blog : blog}
	})
}

export const getEvents = (name,page) => {
	if(!page) page = 1
	let username = uni.getStorageSync("username")
	return http.request({
		url : "v5/users/"+username+"/received_events/public",
		method : "GET",
		data : {access_token:uni.getStorageSync('access_token'),page:page,per_page:20}
	})
	// return http.request({
	// 	url : "v3/events",
	// 	method : "GET",
	// 	data : {private_token:uni.getStorageSync('private_token'),page:page,per_page:5}
	// })
}
// export const getEvents = (name,page) => {
// 	if(!page) page = 1
// 	return http.request({
// 		url : "v3/events",
// 		method : "GET",
// 		data : {private_token:uni.getStorageSync('access_token'),page:page,per_page:5}
// 	})
// }

export const getSomeOneEvents = (name,page) => {
	if(!page) page = 1
	return http.request({
		url : "v5/users/"+name+"/events/public",
		method : "GET",
		data : {private_token:uni.getStorageSync('private_token'),page:page}
	})
}